<?


function get_size_of_box ($array_1) {
	if ($array_1[6] <0 ) {
		$x_new = $array_1[2]+(-1*$array_1[6]);
	}
	else {
		$x_new = $array_1[2]+$array_1[6];
	}
	if ($array_1[7] <0 ) {
		$y_new = $array_1[3]+(-1*$array_1[7]);
	}
	else {
		$y_new = $array_1[3]+$array_1[7];
	}
	$array_2['x'] =  $x_new;
	$array_2['y'] =  $y_new;
	return ($array_2);
}
function make_box_with_text ($bg_color, $text_color, $font_path, $font_size, $angle, $text, $reverse) {
	// descriprion -- $bg_color  and text_color = array (r,g,b)
	if ($reverse == 1) {
		$tmp_1 = $bg_color;
		$bg_color = $text_color;
		$text_color = $tmp_1;
	}
	$im = imagecreatetruecolor (3,3);
	$obj_bg_color = imagecolorallocate($im, $bg_color[0], $bg_color[1], $bg_color[2]);
	$obj_text_color = imagecolorallocate($im, $text_color[0], $text_color[1], $text_color[2]);
	$image_size = imagettfbbox($font_size, $angle, $font_path, $text);
	$im_1_box_size = get_size_of_box($image_size);
	$im_1_box_size['y'] = $im_1_box_size['y']+2;
	$im_tmp_1 = imagecreatetruecolor ($im_1_box_size['x'], $im_1_box_size['y']);
	imagefill ($im_tmp_1, 0, 0, $obj_bg_color);
	imagettftext($im_tmp_1, $font_size, 0, $image_size[0]*-1, $image_size[5]*-1, $obj_text_color, $font_path, $text);
	return (array ($im_tmp_1, $im_1_box_size['x'], $im_1_box_size['y'])); // 0 - image, 1 - size x, 2 - size y
}

function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}

function wireless_signal_colorate ($data_a, $image) {
	static $colormatrix;
	//$max_strange = 17;
	//$mix_strange = -126;
	$start = -30;
	$max_strange = $start;
	$mix_strange = $start-109;

	if (empty($colormatrix)) {
		$r = 250;
		$g = 0;
		$b = 250;
		for ($sigstrange = $max_strange; $sigstrange >= $mix_strange; $sigstrange--) {
			//if ($data_a == 	$sigstrange	) $color = imagecolorallocate($image, $r, $g, $b);
			if (($r == 250) AND ($g >= 0) AND ($b >= 10)) {
				$b = $b - 10;
			}
			elseif (($r == 250) AND ($g <= 240) AND ($b == 0)) {
				$g = $g + 10;
			}
			elseif (($r >= 10) AND ($g >= 250) AND ($b == 0)) {
				$r = $r - 10;
			}
			elseif (($r == 0) AND ($g >= 10) AND ($b <= 240)) {
				$g = $g - 10;
				$b = $b + 10;
			}
			elseif (($r == 0) AND ($g == 0) AND ($b >= 10)) {
				$b = $b - 10;
			}
			$colormatrix[$sigstrange] = imagecolorallocate($image, $r, $g, $b);
		}
		
	}
	if ($data_a > $max_strange) {
		$color = imagecolorallocate($image, 255, 0, 255);
	}
	elseif ($data_a < $mix_strange) {
		$color = imagecolorallocate($image, 0, 0, 0);
	}
	else {
		$color = $colormatrix[$data_a];
	}
	
	/*
	if ($data_a == 	17	) $color = imagecolorallocate($image, 	255	, 	0	, 	250	);
	if ($data_a == 	16	) $color = imagecolorallocate($image, 	255	, 	0	, 	240	);
	if ($data_a == 	15	) $color = imagecolorallocate($image, 	255	, 	0	, 	230	);
	if ($data_a == 	14	) $color = imagecolorallocate($image, 	255	, 	0	, 	220	);
	if ($data_a == 	13	) $color = imagecolorallocate($image, 	255	, 	0	, 	210	);
	if ($data_a == 	12	) $color = imagecolorallocate($image, 	255	, 	0	, 	200	);
	if ($data_a == 	11	) $color = imagecolorallocate($image, 	255	, 	0	, 	190	);
	if ($data_a == 	10	) $color = imagecolorallocate($image, 	255	, 	0	, 	180	);
	if ($data_a == 	9	) $color = imagecolorallocate($image, 	255	, 	0	, 	170	);
	if ($data_a == 	8	) $color = imagecolorallocate($image, 	255	, 	0	, 	160	);
	if ($data_a == 	7	) $color = imagecolorallocate($image, 	255	, 	0	, 	150	);
	if ($data_a == 	6	) $color = imagecolorallocate($image, 	255	, 	0	, 	140	);
	if ($data_a == 	5	) $color = imagecolorallocate($image, 	255	, 	0	, 	130	);
	if ($data_a == 	4	) $color = imagecolorallocate($image, 	255	, 	0	, 	120	);
	if ($data_a == 	3	) $color = imagecolorallocate($image, 	255	, 	0	, 	110	);
	if ($data_a == 	2	) $color = imagecolorallocate($image, 	255	, 	0	, 	100	);
	if ($data_a == 	1	) $color = imagecolorallocate($image, 	255	, 	0	, 	90	);
	if ($data_a == 	0	) $color = imagecolorallocate($image, 	255	, 	0	, 	80	);
	if ($data_a == 	-1	) $color = imagecolorallocate($image, 	255	, 	0	, 	70	);
	if ($data_a == 	-2	) $color = imagecolorallocate($image, 	255	, 	0	, 	60	);
	if ($data_a == 	-3	) $color = imagecolorallocate($image, 	255	, 	0	, 	50	);
	if ($data_a == 	-4	) $color = imagecolorallocate($image, 	255	, 	0	, 	40	);
	if ($data_a == 	-5	) $color = imagecolorallocate($image, 	255	, 	0	, 	30	);
	if ($data_a == 	-6	) $color = imagecolorallocate($image, 	255	, 	0	, 	20	);
	if ($data_a == 	-7	) $color = imagecolorallocate($image, 	255	, 	0	, 	10	);
	if ($data_a == 	-8	) $color = imagecolorallocate($image, 	255	, 	0	, 	0	);
	if ($data_a == 	-9	) $color = imagecolorallocate($image, 	255	, 	10	, 	0	);
	if ($data_a == 	-10	) $color = imagecolorallocate($image, 	255	, 	20	, 	0	);
	if ($data_a == 	-11	) $color = imagecolorallocate($image, 	255	, 	30	, 	0	);
	if ($data_a == 	-12	) $color = imagecolorallocate($image, 	255	, 	40	, 	0	);
	if ($data_a == 	-13	) $color = imagecolorallocate($image, 	255	, 	50	, 	0	);
	if ($data_a == 	-14	) $color = imagecolorallocate($image, 	255	, 	60	, 	0	);
	if ($data_a == 	-15	) $color = imagecolorallocate($image, 	255	, 	70	, 	0	);
	if ($data_a == 	-16	) $color = imagecolorallocate($image, 	255	, 	80	, 	0	);
	if ($data_a == 	-17	) $color = imagecolorallocate($image, 	255	, 	90	, 	0	);
	if ($data_a == 	-18	) $color = imagecolorallocate($image, 	255	, 	100	, 	0	);
	if ($data_a == 	-19	) $color = imagecolorallocate($image, 	255	, 	110	, 	0	);
	if ($data_a == 	-20	) $color = imagecolorallocate($image, 	255	, 	120	, 	0	);
	if ($data_a == 	-21	) $color = imagecolorallocate($image, 	255	, 	130	, 	0	);
	if ($data_a == 	-22	) $color = imagecolorallocate($image, 	255	, 	140	, 	0	);
	if ($data_a == 	-23	) $color = imagecolorallocate($image, 	255	, 	150	, 	0	);
	if ($data_a == 	-24	) $color = imagecolorallocate($image, 	255	, 	160	, 	0	);
	if ($data_a == 	-25	) $color = imagecolorallocate($image, 	255	, 	170	, 	0	);
	if ($data_a == 	-26	) $color = imagecolorallocate($image, 	255	, 	180	, 	0	);
	if ($data_a == 	-27	) $color = imagecolorallocate($image, 	255	, 	190	, 	0	);
	if ($data_a == 	-28	) $color = imagecolorallocate($image, 	255	, 	200	, 	0	);
	if ($data_a == 	-29	) $color = imagecolorallocate($image, 	255	, 	210	, 	0	);
	if ($data_a == 	-30	) $color = imagecolorallocate($image, 	255	, 	220	, 	0	);
	if ($data_a == 	-31	) $color = imagecolorallocate($image, 	255	, 	230	, 	0	);
	if ($data_a == 	-32	) $color = imagecolorallocate($image, 	255	, 	240	, 	0	);
	if ($data_a == 	-33	) $color = imagecolorallocate($image, 	255	, 	250	, 	0	);
	if ($data_a == 	-34	) $color = imagecolorallocate($image, 	250	, 	255	, 	0	);
	if ($data_a == 	-35	) $color = imagecolorallocate($image, 	240	, 	255	, 	0	);
	if ($data_a == 	-36	) $color = imagecolorallocate($image, 	230	, 	255	, 	0	);
	if ($data_a == 	-37	) $color = imagecolorallocate($image, 	220	, 	255	, 	0	);
	if ($data_a == 	-38	) $color = imagecolorallocate($image, 	210	, 	255	, 	0	);
	if ($data_a == 	-39	) $color = imagecolorallocate($image, 	200	, 	255	, 	0	);
	if ($data_a == 	-40	) $color = imagecolorallocate($image, 	190	, 	255	, 	0	);
	if ($data_a == 	-41	) $color = imagecolorallocate($image, 	180	, 	255	, 	0	);
	if ($data_a == 	-42	) $color = imagecolorallocate($image, 	170	, 	255	, 	0	);
	if ($data_a == 	-43	) $color = imagecolorallocate($image, 	160	, 	255	, 	0	);
	if ($data_a == 	-44	) $color = imagecolorallocate($image, 	150	, 	255	, 	0	);
	if ($data_a == 	-45	) $color = imagecolorallocate($image, 	140	, 	255	, 	0	);
	if ($data_a == 	-46	) $color = imagecolorallocate($image, 	130	, 	255	, 	0	);
	if ($data_a == 	-47	) $color = imagecolorallocate($image, 	120	, 	255	, 	0	);
	if ($data_a == 	-48	) $color = imagecolorallocate($image, 	110	, 	255	, 	0	);
	if ($data_a == 	-49	) $color = imagecolorallocate($image, 	100	, 	255	, 	0	);
	if ($data_a == 	-50	) $color = imagecolorallocate($image, 	90	, 	255	, 	0	);
	if ($data_a == 	-51	) $color = imagecolorallocate($image, 	80	, 	255	, 	0	);
	if ($data_a == 	-52	) $color = imagecolorallocate($image, 	70	, 	255	, 	0	);
	if ($data_a == 	-53	) $color = imagecolorallocate($image, 	60	, 	255	, 	0	);
	if ($data_a == 	-54	) $color = imagecolorallocate($image, 	50	, 	255	, 	0	);
	if ($data_a == 	-55	) $color = imagecolorallocate($image, 	40	, 	255	, 	0	);
	if ($data_a == 	-56	) $color = imagecolorallocate($image, 	30	, 	255	, 	0	);
	if ($data_a == 	-57	) $color = imagecolorallocate($image, 	20	, 	255	, 	0	);
	if ($data_a == 	-58	) $color = imagecolorallocate($image, 	10	, 	250	, 	0	);
	if ($data_a == 	-59	) $color = imagecolorallocate($image, 	0	, 	250	, 	0	);
	if ($data_a == 	-60	) $color = imagecolorallocate($image, 	0	, 	240	, 	10	);
	if ($data_a == 	-61	) $color = imagecolorallocate($image, 	0	, 	230	, 	20	);
	if ($data_a == 	-62	) $color = imagecolorallocate($image, 	0	, 	220	, 	30	);
	if ($data_a == 	-63	) $color = imagecolorallocate($image, 	0	, 	210	, 	40	);
	if ($data_a == 	-64	) $color = imagecolorallocate($image, 	0	, 	200	, 	50	);
	if ($data_a == 	-65	) $color = imagecolorallocate($image, 	0	, 	190	, 	60	);
	if ($data_a == 	-66	) $color = imagecolorallocate($image, 	0	, 	180	, 	70	);
	if ($data_a == 	-67	) $color = imagecolorallocate($image, 	0	, 	170	, 	80	);
	if ($data_a == 	-68	) $color = imagecolorallocate($image, 	0	, 	160	, 	90	);
	if ($data_a == 	-69	) $color = imagecolorallocate($image, 	0	, 	150	, 	100	);
	if ($data_a == 	-70	) $color = imagecolorallocate($image, 	0	, 	140	, 	110	);
	if ($data_a == 	-71	) $color = imagecolorallocate($image, 	0	, 	130	, 	120	);
	if ($data_a == 	-72	) $color = imagecolorallocate($image, 	0	, 	120	, 	130	);
	if ($data_a == 	-73	) $color = imagecolorallocate($image, 	0	, 	110	, 	140	);
	if ($data_a == 	-74	) $color = imagecolorallocate($image, 	0	, 	100	, 	150	);
	if ($data_a == 	-75	) $color = imagecolorallocate($image, 	0	, 	90	, 	160	);
	if ($data_a == 	-76	) $color = imagecolorallocate($image, 	0	, 	80	, 	170	);
	if ($data_a == 	-77	) $color = imagecolorallocate($image, 	0	, 	70	, 	180	);
	if ($data_a == 	-78	) $color = imagecolorallocate($image, 	0	, 	60	, 	190	);
	if ($data_a == 	-79	) $color = imagecolorallocate($image, 	0	, 	50	, 	200	);
	if ($data_a == 	-80	) $color = imagecolorallocate($image, 	0	, 	40	, 	210	);
	if ($data_a == 	-81	) $color = imagecolorallocate($image, 	0	, 	30	, 	220	);
	if ($data_a == 	-82	) $color = imagecolorallocate($image, 	0	, 	20	, 	230	);
	if ($data_a == 	-83	) $color = imagecolorallocate($image, 	0	, 	10	, 	240	);
	if ($data_a == 	-84	) $color = imagecolorallocate($image, 	0	, 	0	, 	250	);
	if ($data_a == 	-85	) $color = imagecolorallocate($image, 	0	, 	0	, 	240	);
	if ($data_a == 	-86	) $color = imagecolorallocate($image, 	0	, 	0	, 	230	);
	if ($data_a == 	-87	) $color = imagecolorallocate($image, 	0	, 	0	, 	220	);
	if ($data_a == 	-88	) $color = imagecolorallocate($image, 	0	, 	0	, 	210	);
	if ($data_a == 	-89	) $color = imagecolorallocate($image, 	0	, 	0	, 	200	);
	if ($data_a == 	-90	) $color = imagecolorallocate($image, 	0	, 	0	, 	190	);
	if ($data_a == 	-91	) $color = imagecolorallocate($image, 	0	, 	0	, 	180	);
	if ($data_a == 	-92	) $color = imagecolorallocate($image, 	0	, 	0	, 	170	);
	if ($data_a == 	-93	) $color = imagecolorallocate($image, 	0	, 	0	, 	160	);
	if ($data_a == 	-94	) $color = imagecolorallocate($image, 	0	, 	0	, 	150	);
	if ($data_a == 	-95	) $color = imagecolorallocate($image, 	0	, 	0	, 	140	);
	if ($data_a == 	-96	) $color = imagecolorallocate($image, 	0	, 	0	, 	130	);
	if ($data_a == 	-97	) $color = imagecolorallocate($image, 	0	, 	0	, 	120	);
	if ($data_a == 	-98	) $color = imagecolorallocate($image, 	0	, 	0	, 	110	);
	if ($data_a == 	-99	) $color = imagecolorallocate($image, 	0	, 	0	, 	100	);
	if ($data_a == 	-100	) $color = imagecolorallocate($image, 	0	, 	0	, 	90	);
	if ($data_a == 	-101	) $color = imagecolorallocate($image, 	0	, 	0	, 	80	);
	if ($data_a == 	-102	) $color = imagecolorallocate($image, 	0	, 	0	, 	70	);
	if ($data_a == 	-103	) $color = imagecolorallocate($image, 	0	, 	0	, 	60	);
	if ($data_a == 	-104	) $color = imagecolorallocate($image, 	0	, 	0	, 	50	);
	if ($data_a == 	-105	) $color = imagecolorallocate($image, 	0	, 	0	, 	40	);
	if ($data_a == 	-106	) $color = imagecolorallocate($image, 	0	, 	0	, 	30	);
	if ($data_a == 	-107	) $color = imagecolorallocate($image, 	0	, 	0	, 	20	);
	if ($data_a == 	-108	) $color = imagecolorallocate($image, 	0	, 	0	, 	19	);
	if ($data_a == 	-109	) $color = imagecolorallocate($image, 	0	, 	0	, 	18	);
	if ($data_a == 	-110	) $color = imagecolorallocate($image, 	0	, 	0	, 	17	);
	if ($data_a == 	-111	) $color = imagecolorallocate($image, 	0	, 	0	, 	16	);
	if ($data_a == 	-112	) $color = imagecolorallocate($image, 	0	, 	0	, 	15	);
	if ($data_a == 	-113	) $color = imagecolorallocate($image, 	0	, 	0	, 	14	);
	if ($data_a == 	-114	) $color = imagecolorallocate($image, 	0	, 	0	, 	13	);
	if ($data_a == 	-115	) $color = imagecolorallocate($image, 	0	, 	0	, 	12	);
	if ($data_a == 	-116	) $color = imagecolorallocate($image, 	0	, 	0	, 	11	);
	if ($data_a == 	-117	) $color = imagecolorallocate($image, 	0	, 	0	, 	10	);
	if ($data_a == 	-118	) $color = imagecolorallocate($image, 	0	, 	0	, 	9	);
	if ($data_a == 	-119	) $color = imagecolorallocate($image, 	0	, 	0	, 	8	);
	if ($data_a == 	-120	) $color = imagecolorallocate($image, 	0	, 	0	, 	7	);
	if ($data_a == 	-121	) $color = imagecolorallocate($image, 	0	, 	0	, 	6	);
	if ($data_a == 	-122	) $color = imagecolorallocate($image, 	0	, 	0	, 	5	);
	if ($data_a == 	-123	) $color = imagecolorallocate($image, 	0	, 	0	, 	4	);
	if ($data_a == 	-124	) $color = imagecolorallocate($image, 	0	, 	0	, 	3	);
	if ($data_a == 	-125	) $color = imagecolorallocate($image, 	0	, 	0	, 	2	);
	if ($data_a == 	-126	) $color = imagecolorallocate($image, 	0	, 	0	, 	1	);
	if ($data_a <= 	-127	) $color = imagecolorallocate($image, 	0	, 	0	, 	0	);
	*/
	return ($color);
}

?>